@echo off
echo =============================================
echo 占卜大师自动化编译和测试脚本
echo =============================================

echo.
echo [1/5] 清理之前的构建缓存...
call .\gradlew clean --no-daemon --offline --build-cache

echo.
echo [2/5] 编译Debug版本...
call .\gradlew assembleDebug --no-daemon --offline --build-cache --stacktrace

IF %ERRORLEVEL% NEQ 0 (
    echo 编译失败，尝试在线模式...
    call .\gradlew assembleDebug --no-daemon --build-cache --stacktrace
    IF %ERRORLEVEL% NEQ 0 (
        echo 编译仍然失败，退出
        exit /b 1
    )
)

echo.
echo [3/5] 编译成功！开始运行单元测试...
call .\gradlew test --no-daemon --build-cache --stacktrace

echo.
echo [4/5] 生成测试报告...
echo 测试报告位置: app\build\reports\tests\testDebugUnitTest\index.html

echo.
echo [5/5] 构建完成摘要
echo =============================================
if exist "app\build\outputs\apk\debug\app-debug.apk" (
    echo ✓ APK构建成功: app\build\outputs\apk\debug\app-debug.apk
    for %%I in ("app\build\outputs\apk\debug\app-debug.apk") do echo   文件大小: %%~zI bytes
) else (
    echo ✗ APK构建失败
)

echo.
echo 构建和测试流程完成！
pause
